package edu.asu.cse360.context;

import edu.asu.cse360.service.AuthenticationService;
import edu.asu.cse360.service.EmployeeService;
import edu.asu.cse360.service.MenuItemService;
import edu.asu.cse360.service.ItemOrderService;
import edu.asu.cse360.service.ItemReportService;
import edu.asu.cse360.service.OrderService;
import edu.asu.cse360.service.OrderStatusService;
import edu.asu.cse360.service.PhotoService;
import edu.asu.cse360.service.RestaurantService;
import edu.asu.cse360.service.StaffReportService;
import edu.asu.cse360.service.TableService;
import edu.asu.cse360.service.client.OrderStatusServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;

@Configuration
class RemoteServiceConfig extends ServiceConfig{


    //private static final String CONTEXT_PATH = "http://localhost:8080/cse360-server-0.0.1-SNAPSHOT";
    private static final String CONTEXT_PATH = "http://www.smashingmashups.com/cse360-server-0.0.1-SNAPSHOT";

    private static final String REMOTE_BASE_URL = CONTEXT_PATH + "/remoting";

    @Bean
    @Override
    public HttpInvokerProxyFactoryBean restaurantService(){
        HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
        bean.setServiceInterface(RestaurantService.class);
        bean.setServiceUrl(REMOTE_BASE_URL + "/RestaurantService");
        return bean;
    }

    @Bean
    @Override
    public HttpInvokerProxyFactoryBean authenticationService(){
        HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
        bean.setServiceInterface(AuthenticationService.class);
        bean.setServiceUrl(REMOTE_BASE_URL + "/AuthenticationService");
        return bean;
    }

    @Bean
    @Override
    public HttpInvokerProxyFactoryBean menuItemService(){
        HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
        bean.setServiceInterface(MenuItemService.class);
        bean.setServiceUrl(REMOTE_BASE_URL + "/MenuItemService");
        return bean;
    }

    @Bean
    @Override
    public HttpInvokerProxyFactoryBean itemOrderService(){
        HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
        bean.setServiceInterface(ItemOrderService.class);
        bean.setServiceUrl(REMOTE_BASE_URL + "/ItemOrderService");
        return bean;
    }

    @Bean
    @Override
    public OrderStatusService orderStatusService() {
        return new OrderStatusServiceImpl();
    }

    @Override
    public @Bean Object photoService() {
        HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
        bean.setServiceInterface(PhotoService.class);
        bean.setServiceUrl(REMOTE_BASE_URL + "/PhotoService");
        return bean;
    }

    @Override
    public @Bean Object tableService() {
        HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
        bean.setServiceInterface(TableService.class);
        bean.setServiceUrl(REMOTE_BASE_URL + "/TableService");
        return bean;
    }

    @Override
    public @Bean Object orderService() {
        HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
        bean.setServiceInterface(OrderService.class);
        bean.setServiceUrl(REMOTE_BASE_URL + "/OrderService");
        return bean;
    }

    @Override
    public @Bean Object itemReportService() {
        HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
        bean.setServiceInterface(ItemReportService.class);
        bean.setServiceUrl(REMOTE_BASE_URL + "/ItemReportService");
        return bean;
    }

    @Override
    public @Bean Object staffReportService() {
        HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
        bean.setServiceInterface(StaffReportService.class);
        bean.setServiceUrl(REMOTE_BASE_URL + "/StaffReportService");
        return bean;
    }

    @Override
    public @Bean Object employeeService() {
        HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
        bean.setServiceInterface(EmployeeService.class);
        bean.setServiceUrl(REMOTE_BASE_URL + "/EmployeeService");
        return bean;
    }
}
